package jc.malpractice.service;

import cn.hutool.json.JSONObject;
import jc.malpractice.db.DbUtil;
import jc.malpractice.db.Help;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TestService {
    public static JSONObject list(){
        Connection conn = DbUtil.getConn();
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            if (conn == null && conn.isClosed()) {
                return null;
            }

            preparedStatement = conn.prepareStatement(
                    "SELECT * FROM event,status_table where event.status = status_table.status_id");
            resultSet = preparedStatement.executeQuery();
            System.out.println(resultSet);
            JSONObject r = Help.Result4Json(resultSet);
            preparedStatement.close();
            r.set("code",0);
            return r;
        }catch(Exception ex){
            return null;
        }
        finally {
            try {
                if (resultSet != null) resultSet.close();
                if (preparedStatement != null) preparedStatement.close();
                conn.close();
            } catch (SQLException e) {
                System.out.println(e.getMessage());
            }
        }
    }
}
